package test_junit_shop.ProductStock;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import java.util.List;

/**
 * Created by ZH on 2018/1/29.
 * 门店-快速入库
 */
public class PurchaseInWarehouse {

    private static PurchaseInWarehouse piw = new PurchaseInWarehouse();
    private WebDriver driver;

    public static PurchaseInWarehouse getInstance(){
        return piw;
    }
    public WebDriver getDriver(){
        return driver;
    }
    public void setDriver(WebDriver w){
        driver = w;
    }

//    public void switchMenu() throws InterruptedException {
//        WebElement firstMenu = driver.findElement(By.linkText("产品库存"));
//        firstMenu.click();
//        Thread.sleep(1000);
//        WebElement secondMenu = driver.findElement(By.linkText("订货采购"));
//        secondMenu.click();
//        Thread.sleep(1000);
//        WebElement thirdMenu = driver.findElement(By.linkText("快速采购入库"));
//        thirdMenu.click();
//    }

    public void purchaseInWarehouse() throws InterruptedException {
        Thread.sleep(1000);
        driver.switchTo().frame(driver.findElement(By.name("iframeundefined")));
        WebElement vendor = driver.findElement(By.id("search_name"));
        vendor.sendKeys("T");
        Thread.sleep(1000);
        vendor = driver.findElement(By.xpath("//i[contains(text(), 'TEST')]"));
        new Actions(driver).moveToElement(vendor);
        Thread.sleep(1000);
        vendor.click();
        Thread.sleep(1000);
        // 输入产品名
        WebElement productName = driver.findElement(By.xpath("//input[@placeholder='输入产品关键词']"));
        productName.sendKeys("测");
        Thread.sleep(1000);
        productName = driver.findElement(By.xpath("//input[@placeholder='输入产品关键词']/following-sibling::div/table/tbody/tr[1]/td[1]"));
        new Actions(driver).moveToElement(productName);
        Thread.sleep(1000);
        productName.click();
        Thread.sleep(1000);
        // 输入单价
        WebElement unitPrice = driver.findElement(By.xpath("//input[@placeholder='输入产品关键词']/../following-sibling::td[6]/input"));
        unitPrice.sendKeys("1200");
        WebElement amount = driver.findElement(By.xpath("//input[@placeholder='输入产品关键词']/../following-sibling::td[7]/input"));
        amount.sendKeys("500");
        WebElement settle = driver.findElement(By.xpath("//button[contains(text(), '结算')]"));
        settle.click();
        Thread.sleep(1000);
        WebElement comfirm = driver.findElement(By.linkText("确定"));
        comfirm.click();
        Thread.sleep(1000);

        List<WebElement> comfirms = driver.findElements(By.linkText("确定"));
        comfirms.get(1).click();
    }
}
